<template>
  <div class="home contentBox">
    <div>
      <pro-list
        title="问题处理"
        :list="proList"
        list-name="before_process"
        detail-name="Prohandledetail"
      />
    </div>
    <div>
      <list
        title="论坛"
        :list="disList"
        list-name="Discuss"
        detail-name="Discussdetail"
      />
    </div>
  </div>
</template>
<script>
import list from './list'
import proList from './proList'
import { mapGetters } from 'vuex'
export default {
  components: {
    list,proList
  },
  data() {
    return {
      disList: [],
      proList: [],
      searchObj: {
        userId: '',
        deptId: '',
        cateCode: ''
      },
      account:JSON.parse(sessionStorage.getItem('user')).account
    }
  },
  computed: {
    ...mapGetters(['userId', 'deptId'])
  },
  created() {
    this.$set(this.searchObj, 'userId', this.userId)
    this.$set(this.searchObj, 'deptId', this.deptId)
    this.getForumList(this.searchObj, { current: 1, limit: 10 })
    this.getProcessList()
  },
  methods: {
    getForumList(searchObj, pageObj) {
      const pms = Object.assign(searchObj, pageObj)
      this.$axios
        .post('/forum/list', pms)
        .then(res => {
          this.disList = res.data.records
        })
        .catch(() => {
        })
    },
    getProcessList(){
      const queryParams = {
        'ACT_RU_TASK:data[]': {
          '@column': 'ID_:taskId,PROC_INST_ID_:procInstId,name_:node_name,PROC_DEF_ID_:procDefID',
          '@where':{
            'id_@in':`SELECT DISTINCT ( a.id_ ) FROM ACT_RU_TASK a LEFT JOIN ACT_RU_IDENTITYLINK b ON a.id_ = b.TASK_ID_ LEFT JOIN sys_position c ON b.GROUP_ID_ = c.CODE LEFT JOIN sys_user_pos d ON c.position_id = d.pos_id LEFT JOIN sys_user e ON d.user_id = e.user_id LEFT JOIN (SELECT c.pids AS dept_pids,a.id_ FROM ACT_RU_TASK a LEFT JOIN act_hi_procinst proc ON a.PROC_INST_ID_ = proc.id_ LEFT JOIN sys_user b ON proc.START_USER_ID_ = b.account LEFT JOIN sys_dept c ON b.dept_id = c.dept_id  ) m ON a.id_ = m.id_  WHERE a.assignee_ = '${this.account}' OR b.user_id_ = '${this.account}' OR ( e.account = '${this.account}' and m.dept_pids like '%${this.deptId}%') `
          },
          '@page': {
            '@pageSize': 10,
            '@pageNo': 1
          },
          '@join': [
            {
              'ACT_RE_PROCDEF@leftOutJoin': {
                '@column': 'name_:process_name,KEY_:procDefKey',
                '@on': {
                  'ID_': 'data/PROC_DEF_ID_'
                },
                '@where': {
                  'name_@like': '%%'
                }
              }
            },
            {
              'ACT_HI_PROCINST@leftOutJoin': {
                '@column': 'START_TIME_:start_time,START_USER_ID_:startUser',
                '@on': {
                  'ID_': 'data/proc_inst_id_'
                },
                '@order':'START_TIME_-'
              }
            },
            {
              'SYS_USER@leftOutJoin': {
                '@column': 'account,name',
                '@on': {
                  'account': 'ACT_HI_PROCINST/START_USER_ID_'
                },
                '@where': {
                  'account@like': '%%'
                }
              }
            }
          ]
        }
      }
      this.COM.jsonsqlForSelect(queryParams).then(res=>{
        this.proList = res.data
        console.log('this.proList:', this.proList)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  display: flex;
  justify-content: space-between;
  & > div {
    width: 49%;
  }
}
</style>
